﻿using DevLib.TestCase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;


/** 
 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
 * Description: 
 * Author: Heller (HellerSong@outlook.com)
 * CreationTime: 3/19/2015 7:55:36 AM
 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** 
 **/
namespace DevLib.SuperTool
{
	public class DevRegex
	{
		/*
		 * Match value, used for getting matched sub string.
		 */
		public static String MatchSentenceInteger = @"-{0,1}\d+";
        public static String MatchSentencePositiveInteger = @"\d+";
        public static String MatchSentenceNegativeInteger = @"-\d+";
        public static String MatchWord = @"[A-Za-z]([a-z]+|[A-Z]+)";
        public static String MatchCNWord = @"[\u2E80-\u9FFF]+";

		/*
		 * Check value, used for validating full string is what format you want.
		 */
        public static String CheckPassword = "^[a-z0-9_-]{6,18}$";
        public static String CheckInteger = @"^-{0,1}\d+$";
        public static String CheckPositiveInteger = @"^\d+$";
        public static String CheckNegativeInteger = @"^-\d+$";
        public static String CheckIPv4 = @"^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]){3}$";
        public static String CheckPhoneNumber = @"^\+?[\d\s]{3,}$";
        public static String CheckEmail = @"^[\_]*([a-z0-9]+(\.|\_*)?)+@([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}$";
        public static String CheckStartWithDoes = @"^(D|d)oes\w*";

        private DevRegex() { }


        public static Boolean CheckIsMatch(String input, String checkPattern)
        {
            StrCheck.CheckChainArgUsable(input);
			StrCheck.CheckChainArgUsable(checkPattern);

            return new Regex(checkPattern).IsMatch(input);
        }

        public static String GetMatchedString(String input, String matchPattern)
        {
			StrCheck.CheckChainArgUsable(input);
			StrCheck.CheckChainArgUsable(matchPattern);

            return new Regex(matchPattern).Match(input).Value;
        }
        public static String[] GetMatchedStringArray(String input, String matchPattern)
        {
			StrCheck.CheckChainArgUsable(input);
			StrCheck.CheckChainArgUsable(matchPattern);

            List<String> list = new List<string>();
            Regex regex = new Regex(matchPattern);

            foreach (Match m in regex.Matches(input))
                list.Add(m.Value);

            return list.ToArray();
        }

	}
}
